package chapter_13_proxy.normal_proxy;

/**
 * Created by CharloYao on 2017/10/11.
 * 代理类
 */
public class Proxy implements Subject {

    private Subject subject;

    public Proxy() {
        this.subject = new Proxy(); //默认被代理者
    }

    //通过构造函数传递被代理者
    public Proxy(Subject subject) {
        this.subject = subject;
    }

    //实现接口中定义的方法
    @Override
    public void request() {
        before();

        subject.request();

        after();
    }

    //预处理
    private void before(){
        System.out.println("before...");
    }

    //后处理
    private void after(){
        System.out.println("after...");
    }
}
